home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / LV1WS.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  863b  |  37 lines

  1. /*
  2. **  Originally published as part of the MicroFirm Function Library
  3. **
  4. **  Copyright 1987-88, Robert B.Stout
  5. **
  6. **  Subset version released to the public domain, 1992
  7. **
  8. **  Makes all whitespace single spaces. Passed a string, lv1ws()
  9. **  converts all multiple whitespace characters to single spaces.
  10. */
  11.  
  12. #include <ctype.h>
  13.  
  14. void lv1ws(char *str)
  15. {
  16.       char *ibuf = str, *obuf = str;
  17.       int i = 0, cnt = 0;
  18.  
  19.       while(*ibuf)
  20.       {
  21.             if(isspace(*ibuf) && cnt)
  22.                   ibuf++;
  23.             else
  24.             {
  25.                   if (!isspace(*ibuf))
  26.                         cnt = 0;
  27.                   else
  28.                   {
  29.                         *ibuf = ' ';
  30.                         cnt = 1;
  31.                   }
  32.                   obuf[i++] = *ibuf++;
  33.             }
  34.       }
  35.       obuf[i] = '\0';
  36. }
  37.